//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package mm.chenchen.common.utils;

import java.nio.ByteBuffer;
import java.util.UUID;

public class UuidUtil {
    private static final char[] HEX_CHAR = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    public UuidUtil() {
    }

    public static String bytesToString(byte[] bytes) {
        char[] buf = new char[bytes.length * 2];
        int index = 0;
        byte[] var3 = bytes;
        int var4 = bytes.length;

        for(int var5 = 0; var5 < var4; ++var5) {
            byte b = var3[var5];
            buf[index++] = HEX_CHAR[b >>> 4 & 15];
            buf[index++] = HEX_CHAR[b & 15];
        }

        return new String(buf);
    }

    public static byte[] stringToBytes(String str) {
        if (str != null && !str.trim().equals("")) {
            byte[] bytes = new byte[str.length() / 2];

            for(int i = 0; i < str.length() / 2; ++i) {
                String subStr = str.substring(i * 2, i * 2 + 2);
                bytes[i] = (byte)Integer.parseInt(subStr, 16);
            }

            return bytes;
        } else {
            return null;
        }
    }

    public static byte[] uUidToBytes(UUID uuid) {
        ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
        bb.putLong(uuid.getMostSignificantBits());
        bb.putLong(uuid.getLeastSignificantBits());
        return bb.array();
    }

    public static String uUidToString(UUID uuid) {
        return uuid.toString().replace("-", "");
    }
}
